package com.abl.consumer.controller;

import com.abl.consumer.api.ProviderApi;
import com.abl.consumer.fallback.EchoFallBack;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EchoController {
    @Resource
    private ProviderApi providerApi;

    @RequestMapping(value = "/consumer/provider/add/{string}")
    @SentinelResource(fallbackClass = EchoFallBack.class, defaultFallback = "consumerAddFallBack")
    public String consumerAdd(@PathVariable("string") String string) {
        return providerApi.providerAdd(string);
    }

    @RequestMapping(value = "/consumer/provider/sub/{string}")
    @SentinelResource(fallbackClass = EchoFallBack.class, defaultFallback = "consumerSubFallBack")
    public String consumerSub(@PathVariable("string") String string) {
        return providerApi.providerSub(string);
    }

//    public String consumerAddFallBack(Throwable t) {
//        if (BlockException.isBlockException(t)) {
//            return "providerAddFallBack, 异常 CallBack: " + t.getClass().getSimpleName();
//        }
//        return "providerAddFallBack, 异常 CallBack: " + t.getClass().getCanonicalName();
//    }

//    public String consumerSubFallBack(Throwable t) {
//        if (BlockException.isBlockException(t)) {
//            return "providerSubFallBack, 异常 CallBack: " + t.getClass().getSimpleName();
//        }
//        return "providerSubFallBack, 异常 CallBack: " + t.getClass().getCanonicalName();
//    }

}
